﻿/*******************************************************************************************************
 * Code to hide javascript errors
 * http://dave.thehorners.com/tech-talk/programming/389-net-wpf-saying-goodby-to-win32-and-winforms
 * 
 * 
 * Code for jumplist
 * http://www.codeguru.com/csharp/.net/net_general/tipstricks/article.php/c16621__2/Creating-Windows-7-Jump-Lists-With-The-API-Code-Pack-and-Visual-Studio-2008.htm
 ********************************************************************************************************/

using System;
using System.Runtime.InteropServices;
using System.Windows;
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Taskbar;

namespace RSSFeedReader.Views
{
    /// <summary>
    /// Interaction logic for MainView.xaml
    /// </summary>
    public partial class MainView : Window
    {
        [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [Guid("6d5140c1-7436-11ce-8034-00aa006009fa")]
        internal interface IServiceProvider
        {
            [return: MarshalAs(UnmanagedType.IUnknown)]
            object QueryService(ref Guid guidService, ref Guid riid);
        }

        static readonly Guid SID_SWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");

        /// <summary>
        /// Initialize a new instance of the <see cref="MainView"/> class.
        /// </summary>
        public MainView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Handler for when the browser navigates to a site.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WebBrowserNavigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            MakeComBrowserSilent();
        }

        /// <summary>
        /// Hides javascript errors.
        /// </summary>
        private void MakeComBrowserSilent()
        {
            Guid serviceGuid = SID_SWebBrowserApp;
            Guid iid = typeof(SHDocVw.IWebBrowser2).GUID;
            IServiceProvider serviceProvider = (IServiceProvider)webBrowser.Document;
            if (serviceProvider != null)
            {
                SHDocVw.IWebBrowser2 comBrowser = (SHDocVw.IWebBrowser2)serviceProvider.QueryService(ref serviceGuid, ref iid);
                if (comBrowser != null)
                {
                    comBrowser.Silent = true;
                }
            }
        }

        //private void GlassWindow_Loaded(object sender, RoutedEventArgs e)
        //{
        //    if (Environment.OSVersion.Version < new Version(6, 0))
        //    {
        //        mainBorder.Margin = new Thickness(0);
        //    }
        //    else
        //    {
        //        // update GlassRegion on window size change
        //        SizeChanged += new SizeChangedEventHandler(Window1_SizeChanged);

        //        // update background color on change of desktop composition mode
        //        AeroGlassCompositionChanged += new EventHandler<AeroGlassCompositionChangedEventArgs>(Window1_AeroGlassCompositionChanged);

        //        // Set the window background color
        //        if (AeroGlassCompositionEnabled)
        //        {
        //            // exclude the GDI rendered controls from the initial GlassRegion
        //            ExcludeElementFromAeroGlass(mainDockPanel);
        //            SetAeroGlassTransparency();
        //        }
        //        else
        //        {
        //            Background = System.Windows.Media.Brushes.CadetBlue;
        //        }
        //    }

        //    if (TaskbarManager.IsPlatformSupported)
        //    {
        //        JumpList jl;
        //        try
        //        {
        //            jl = JumpList.CreateJumpList();
        //            jl.ClearAllUserTasks();
        //            string selfPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

        //            JumpListLink newFeedCommandTask = new JumpListLink(selfPath, "Add New Feed");
        //            newFeedCommandTask.Arguments = RSSFeedReaderApplication.ADD_NEW_FEED_COMMAND;
        //            string addIcon = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Images\\add.ico");
        //            newFeedCommandTask.IconReference = new IconReference(addIcon, 0);

        //            jl.AddUserTasks(newFeedCommandTask);
        //            jl.Refresh();
        //        }
        //        catch (Exception) { }
        //    }
        //}

        //private void Window1_AeroGlassCompositionChanged(object sender, AeroGlassCompositionChangedEventArgs e)
        //{
        //    // When the desktop composition mode changes the background color and window exclusion must be changed appropriately.
        //    if (e.GlassAvailable)
        //    {
        //        SetAeroGlassTransparency();
        //        ExcludeElementFromAeroGlass(mainDockPanel);
        //        InvalidateVisual();
        //    }
        //    else
        //    {
        //        Background = System.Windows.Media.Brushes.CadetBlue;
        //    }
        //}

        //private void Window1_SizeChanged(object sender, SizeChangedEventArgs e)
        //{
        //    ExcludeElementFromAeroGlass(mainDockPanel);
        //}
    }
}
